/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-04-28
 * Time: 18:47
 */
public class Main {
    /**
     * 斐波那契数:1 1 2 3 5..，n是项数
     * @param n
     * @return
     */
    public static int fib2(int n) {
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main(String[] args) {
        System.out.println(fib2(5));
    }


    //递归法
    public static int fib(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return fib(n-1) + fib(n-2);
    }
    public static void main3(String[] args) {
        System.out.println(fib(6));

    }



    public static int getSum(int n) {
        if (n < 10) {
            return n;
        }
        return (n % 10) + getSum(n / 10);
    }
    public static void main2(String[] args) {
        int ret = getSum(17);
        System.out.println(ret);
    }



    public static int sum(int a) {
        if (a == 1) {
            return 1;
        }
        return a + sum(a-1);
    }
    public static void main1(String[] args) {
        int ret = sum(10);
        System.out.println(ret);
    }



    public static void print(int n) {
        /*if (n < 10) {
            System.out.println(n);
            return;
        }
        print(n / 10);
        System.out.println(n % 10);*/
        if (n > 9) {
            print(n / 10);
        }
        System.out.println(n % 10);
    }
    public static void main0(String[] args) {
        print(123);
    }
}
